package com.lottery.im.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.listener.OnItemSelectedListener;
import com.contrarywind.view.WheelView;
import com.lottery.im.R;
import com.lottery.im.util.ScreenUtils;
import java.util.ArrayList;
import java.util.List;

public class LongDragonSelectDialog {
  private static Dialog mDialog;

  public Dialog create(Context context, View.OnClickListener listener,
      OnItemSelectedListener listener2) {
    mDialog = new Dialog(context, R.style.BottomSelectDialogTheme);
    Window window = mDialog.getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    mDialog.setContentView(R.layout.dialog_long_dragon_select);
    window.setGravity(Gravity.BOTTOM);
    window.setWindowAnimations(R.style.bottom_animation);
    WindowManager.LayoutParams params = window.getAttributes();
    params.width = ScreenUtils.getWidth(context);
    window.setAttributes(params);
    WheelView wheelView = mDialog.findViewById(R.id.wheelView);
    mDialog.findViewById(R.id.tv_dialog_confirm).setOnClickListener(listener);
    mDialog.findViewById(R.id.tv_dialog_cancel).setOnClickListener(v -> mDialog.dismiss());
    wheelView.setCyclic(false);
    wheelView.setTextSize(22);
    wheelView.setTextColorOut(context.getResources().getColor(R.color.gray_99));
    wheelView.setTextColorCenter(context.getResources().getColor(R.color.blue_4f));
    final List<String> mOptionsItems = new ArrayList<>();
    for (int i = 2; i < 11; i++) {
      mOptionsItems.add(i + "");
    }
    wheelView.setAdapter(new ArrayWheelAdapter(mOptionsItems));
    wheelView.setOnItemSelectedListener(listener2);
    return mDialog;
  }

  public static void dismiss() {
    if (mDialog != null) {
      mDialog.dismiss();
    }
    mDialog = null;
  }
}
